home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / sbin / opengl-update < prev    next >
Text File  |  2006-04-12  |  4KB  |  168 lines

  1. #!/bin/bash
  2. # Copyright 1999-2004 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. # $Header: /var/cvsroot/gentoo-x86/x11-base/opengl-update/files/opengl-update-3.0.0,v 1.4 2005/08/17 21:51:02 eradicator Exp $
  5. # Author:  Martin Schlemmer <azarah@gentoo.org>
  6. # Further modifications by Donnie Berkholz <spyderous@gentoo.org>
  7. # Further modifications based off submissions to bug #54984 <cyfred@gentoo.org>
  8. # Further modifications by Jeremy Huddleston <eradicator@gentoo.org>
  9.  
  10. . /etc/init.d/functions.sh
  11.  
  12. hasq() {
  13.     local x
  14.  
  15.     local me=${1}
  16.     shift
  17.         
  18.     for x in "${@}"; do
  19.         if [[ "${x}" == "${me}" ]]; then
  20.             return 0
  21.         fi
  22.     done
  23.     return 1
  24. }
  25.  
  26. print_usage() {
  27.     cat << FOO
  28. Usage: ${0##*/} [<options>] <GL implementation>
  29.        Set the opengl implementation.
  30.        Valid options:
  31.        --use-old:          If an implementation is already set, use that one.
  32.        --prefix=<val>:     Set the source prefix (default: /usr)
  33.        --dst-prefix=<val>: Set the destination prefix (default: /usr)
  34.        --impl-headers:     Use headers provided by this implementation to
  35.                            override golbal ones provided by opengl-update.
  36.  
  37. Usage: ${0##*/} --get-implementation
  38.        Print the current implementaion
  39.  
  40. Notes:
  41.        --impl-headers was default in <opengl-update-2.2.
  42.  
  43. Examples:
  44.        ${0##*/} xorg-x11
  45.        This will setup things to use libGL.so from X.org.
  46.  
  47.        ${0##*/} nvidia
  48.        This will setup things to use libGL.so from the nVidia drivers.
  49.  
  50. WARNING: opengl-update is deprecated and is just a frontend to the opengl
  51.          eselect module.  In the future, opengl-update will be removed
  52.          from portage.  Please see 'eselect opengl help'
  53.  
  54. FOO
  55. }
  56.  
  57. get_implementations() {
  58.     local implems
  59.     for dir in ${PREFIX}/lib{,32,64}/opengl/*; do 
  60.         if [[ -d "${dir}" && ${dir##*/} != "global" ]] && ! hasq ${dir##*/} ${implems}; then
  61.             implems=${implems:+${implems} }${dir##*/}
  62.         fi
  63.     done
  64.     echo ${implems}
  65. }
  66.  
  67. parse_options() {
  68.     local opt
  69.     while [[ ${#} -gt 0 ]]; do
  70.         opt=${1}
  71.         shift
  72.         case ${opt} in
  73.             --use-old)
  74.                 if [[ -n "${ACTION}" ]]; then
  75.                     ACTION="error"
  76.                     eerror "Invalid usage."
  77.                 else
  78.                     if [[ -n "${CURRENT_GL_IMPLEM}" ]] && hasq ${CURRENT_GL_IMPLEM} ${AVAIL_IMPLEMS}; then
  79.                         ACTION="old-implementation"
  80.                     fi
  81.                 fi                
  82.             ;;
  83.             --get-implementation)
  84.                 if [[ -n "${ACTION}" ]]; then
  85.                     ACTION="error"
  86.                     eerror "Invalid usage."
  87.                 else
  88.                     ACTION="get-implementation"
  89.                 fi                
  90.             ;;
  91.             --prefix=*)
  92.                 PREFIX=${opt#*=}
  93.                 AVAIL_IMPLEMS=$(get_implementations)
  94.             ;;
  95.             --dst-prefix=*)
  96.                 DST_PREFIX=${opt#*=}
  97.             ;;
  98.             --impl-headers)
  99.                 USE_PROFILE_HEADERS="yes"
  100.             ;;
  101.             --help|-h|-?)
  102.                 ACION="usage"
  103.             ;;
  104.             *)
  105.                 if hasq ${opt} ${AVAIL_IMPLEMS}; then
  106.                     if [[ "${ACTION}" != "old-implementation" ]]; then
  107.                         if [[ -n "${ACTION}" ]]; then
  108.                             ACTION="error"
  109.                             eerror "Invalid usage."
  110.                         else
  111.                             ACTION="set-implementation"
  112.                             NEW_GL_IMPLEM="${opt}"
  113.                         fi
  114.                     fi                
  115.                 else
  116.                     eerror "Unrecognized option: ${opt}"
  117.                     ACTION="error"
  118.                 fi
  119.             ;;
  120.         esac
  121.     done
  122. }
  123.  
  124. ## START PROGRAM ##
  125.  
  126. NEW_GL_IMPLEM=""
  127. ACTION=""
  128. PREFIX="/usr"
  129. DST_PREFIX="/usr"
  130. AVAIL_IMPLEMS=$(get_implementations)
  131. CURRENT_GL_IMPLEM=$(eselect opengl show)
  132. USE_PROFILE_HEADERS="no"
  133.  
  134. parse_options ${@}
  135.  
  136. case ${ACTION} in
  137.     get-implementation)
  138.         eselect opengl show
  139.     ;;
  140.     old-implementation)
  141.         ewarn "opengl-update is deprecated and is just a frontend to the opengl"
  142.         ewarn "eselect module.  In the future, opengl-update will be removed"
  143.         ewarn "from portage.  Please see 'eselect opengl help'"
  144.  
  145.         eselect opengl set --use-old
  146.         exit $?
  147.     ;;
  148.     set-implementation)
  149.         ewarn "opengl-update is deprecated and is just a frontend to the opengl"
  150.         ewarn "eselect module.  In the future, opengl-update will be removed"
  151.         ewarn "from portage.  Please see 'eselect opengl help'"
  152.  
  153.         if [[ ${USE_PROFILE_HEADERS} == "yes" ]] ; then
  154.             eselect opengl set ${NEW_GL_IMPLEM} --prefix="${PREFIX}" --dst-prefix="${DST_PREFIX}" --impl-headers
  155.         else
  156.             eselect opengl set ${NEW_GL_IMPLEM} --prefix="${PREFIX}" --dst-prefix="${DST_PREFIX}"
  157.         fi
  158.     ;;
  159.     usage)
  160.         print_usage
  161.         exit 0
  162.     ;;
  163.     *)
  164.         print_usage
  165.         exit 1
  166.     ;;
  167. esac
  168.